import Vue from "vue"
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state:{
		showError:true,
		oldUrl:'',
		subscribeDay:uni.getStorageSync("subscribeDay") ? uni.getStorageSync("subscribeDay") : '', //当前订阅日期
		userInfo:uni.getStorageSync("userInfo") ? uni.getStorageSync("userInfo") : {}, //用户信息
		token:uni.getStorageSync("token") ? uni.getStorageSync("token") : '', //用户信息
	},
	mutations:{
		//修改订阅日期
		ChangeSubscribeDay(state,subscribeDay){
			try {
			    uni.setStorageSync('subscribeDay', subscribeDay);
			} catch (e) {}
			state.subscribeDay = subscribeDay
		},
		ChangeShowError(state,showError){
			try {
			    uni.setStorageSync('showError', showError);
			} catch (e) {}
			state.showError = showError
		},
		ChangeOldUrl(state,oldUrl){
			try {
			    uni.setStorageSync('oldUrl', oldUrl);
			} catch (e) {}
			state.oldUrl = oldUrl
		},
		ChangeUserInfo(state,userInfo){
			try {
			    uni.setStorageSync('userInfo', userInfo);
			} catch (e) {}
			state.userInfo = userInfo
		},
		ChangeToken(state,token){
			try {uni.setStorageSync('token', token)} catch (e) {}
			state.token = token
		}
	}
})

export default store